import javax.imageio.ImageIO;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

/**
 * @author zhaozeyang
 * @date 2018/11/8 15:55
 * @description
 */
public class 获取宽高 {

    public static void main(String[] args) {
        getWidthAndHeight("https://static-xesapi.speiyou.cn/1541659216260.jpg");
    }


    /**
     * 获取网络图片的宽和高
     *
     * @param url
     * @return
     */
    public static String getWidthAndHeight(String url) {
        try {
            InputStream is = new URL(url).openStream();
            BufferedImage sourceImg = ImageIO.read(is);
            int width = sourceImg.getWidth();
            int height = sourceImg.getHeight();
            System.out.println(width+":"+height);
            return width + "*" + height;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return "";
    }
}
